package com.wwj.study.interview.chapter1;

public class SingletonDemo {

    private static SingletonDemo singletonDemo=new SingletonDemo();
    //静态成员变量，类加载准备阶段时候就会加载 默认都是0
    public static int count;
    public static int count1=0;//有赋默认值的操作，在类初始化阶段，会重新复制给count1 =0

    public SingletonDemo() {
        count++;  //1
        count1++; //1

        System.out.println("构造方法count="+count);
        System.out.println("构造方法count="+count1);
    }

    private static SingletonDemo getInstance(){
        return singletonDemo;
    }

    public static void main(String[] args) {
        SingletonDemo singletonDemo= SingletonDemo.getInstance();

        System.out.println("count="+count);
        System.out.println("count="+count1);
    }
}
